package com.ljh.oj.model.enums;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author ljh
 * 判题状态
 */
public enum QuestionSubmitEnum {
    // 0 - 待判题、1 - 判题中、2 - 成功、3 - 失败
    WAITING("等待中", 0),
    RUNNING("判题中", 1),
    SUCCEED("成功", 2),
    FAILED("失败", 3);

    public String getText() {
        return text;
    }

    private final String text;

    public Integer getValue() {
        return value;
    }

    private final Integer value;

    QuestionSubmitEnum(String text, Integer value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 获取枚举值列表
     * @return
     */
    public static List<Integer> getValues() {
        return Stream.of(QuestionSubmitEnum.values())
                .map(QuestionSubmitEnum::getValue)
                .collect(Collectors.toList());
    }

    /**
     * 根据value获取text
     * @param value
     * @return
     */
    public static QuestionSubmitEnum getEnum(Integer value) {
        if(value==null){
            return null;
        }
        final QuestionSubmitEnum[] values = QuestionSubmitEnum.values();
        for (QuestionSubmitEnum item : values) {
            if(item.getValue().equals(value)){
                return item;
            }
        }
        return null;
    }
}
